#include "attribute_handle.h"

void attribute_handle_data(u8 *data,u16 len,DATA_SOURCE source)
{
    printf("source %d\n",source);
    if (source == TCP_SOURCE) //判断数据来源
    {
        //set_rec_message(&data[16]);
        //ACK_report();
    }

    for(int i=20;i<len;) //for循环缺省判断
    {
        u32 target=0;
        target |= data[i+0];
        target |= data[i+1] << 8;
        target |= data[i+2] << 16;
        target |= data[i+3] << 24;
        printf("i is %lx\n",target);


        switch (target)
        {

            case DIRE_MODE: //方向设置
                u8 num3 = data[i+4];
                set_direction_handle(num3);
            break;
            
            case MAIN_MODE: //主模式切换
                u8 num4 = data[i+4]; //主模式值
                main_mode_handle(num4);
                i+=(4+1);
                LOG_INFO("set main mode is%d,i is %d\n",num4,i);
            break;

            case MICRO_SENST: //麦克风模式灵敏度
                u8 num5 = data[i+4];
                i+=(4+1);
                set_senst_level_handle(num5);
                LOG_INFO("set micro senst is%d,i is %d\n",num5,i);
            break;

            case SPECTRAL_MODE: //音乐频谱模式
                u8 num9 = data[i+4];
                i+=(4+1);
                set_micro_ssp_handle(num9);
                LOG_INFO("set spectral mode is%d,i is %d\n",num9,i);
            break;

            case SCENE_MODE: //场景模式
                u8 num10 = data[i+4];
                set_scene_handle(num10);
                LOG_INFO("SCENE_MODE %d\n",num10);
                i+=(4+1);
            break;  

            case OPEN_CLOSE:
                u8 num15 = data[i+4];
                if(num15 ==0x01)
                {
                    app_logic_set_ssp(SSP_POWER_OFF);
                }
                else if(num15 == 0x02)
                {
                    app_logic_set_ssp(app_logic_get_recover_ssp());
                }
                i+=(4+1);
                LOG_INFO("set OPEN_CLOSE is%d,i is %d\n",num15,i);
            break;

            case HIGH_SPEED: //高速模式包
                u8 num17 = (data[i+5]<<8|data[i+4]);
                LOG_INFO("high spped data is %d\n",num17);
                set_high_speed_handle(num17,&data[i+6]);
                i+=(4+2+num17);
            break;
            
            case LEVEL_CW: //CW 色温
                u8 num18 =data[i+4]; 
                CW_level_handle(num18);
                i +=(4+1);
            break;

            case BRIGHNESS_CW: //CW 亮度
                u8 num19 =data[i+4]; 
                CW_brighness_handle(num19);
                i +=(4+1);
            break;


            case PART_DATA: //分段信息
                part_info.len = data[i+4];
                memcpy(part_info.RGB,&data[i+5],part_info.len*3);
                i+=(4+1+45);
            break;

            case REGISTER: //重发注册包
                send_register_package();
                i+=4;
            break;
                
            case INQUIRE: //查询指令
                iot_report_init();
                i +=4;
            break;
                

                

        




            
            default:
                LOG_INFO("Instruction number parsing error\n");
                i+=1024;
            break;
        }
    }

}
